package com.day1.t1;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    /*public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.valueOf(in.nextLine());
        List<Integer> list = Arrays.asList(in.nextLine().split(" "))
                .stream()
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        if(n==0){
            System.out.println(0);
            return;
        }
        System.out.println(dps(list,n,0,0,0));
    }

    private static int dps(List<Integer> list, int n, int i,int sum,int cnt){
        if(i==n){
            return sum;
        }
        return Math.max(
                dps(list,n,i+1,sum+list.get(i)+((cnt+1)%10)*list.get(i),cnt+1),
                dps(list,n,i+1,sum+i+1,cnt)
        );
    }*/
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.valueOf(in.nextLine());
        int[] array = Arrays.asList(in.nextLine().split(" "))
                .stream()
                .mapToInt(Integer::parseInt)
                .toArray();
        if(n==0){
            System.out.println(0);
            return;
        }
        int[] dp=new int[n+1];
        int cnt=0;
        dp[0]=0;
        for (int i = 1; i <n+1 ; i++) {
            int a=i;
            int b=array[i-1]+((cnt+1)%10)*array[i-1];
            if(a>b){
                dp[i]=dp[i-1]+a;
            }else{
                dp[i]=dp[i-1]+b;
                cnt++;
            }
        }
        System.out.println(dp[n]);
    }
}
